<!DOCTYPE html>

<html>
  <head>
    <meta charset="utf-8">
    
    <title>Linear algebra (numpy.linalg) &mdash; NumPy v1.18 Manual</title>
    
    <link rel="stylesheet" type="text/css" href="../_static/css/spc-bootstrap.css">
    <link rel="stylesheet" type="text/css" href="../_static/css/spc-extend.css">
    <link rel="stylesheet" href="../_static/scipy.css" type="text/css" >
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" >
    <link rel="stylesheet" href="../_static/graphviz.css" type="text/css" >
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '1.18.1',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  false
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <script type="text/javascript" src="../_static/language_data.js"></script>
    <script type="text/javascript" src="../_static/js/copybutton.js"></script>
    <link rel="author" title="About these documents" href="../about.html" >
    <link rel="index" title="Index" href="../genindex.html" >
    <link rel="search" title="Search" href="../search.html" >
    <link rel="top" title="NumPy v1.18 Manual" href="../index.html" >
    <link rel="up" title="Routines" href="routines.html" >
    <link rel="next" title="numpy.dot" href="generated/numpy.dot.html" >
    <link rel="prev" title="numpy.lib.format" href="generated/numpy.lib.format.html" > 
  </head>
  <body>
<div class="container">
  <div class="top-scipy-org-logo-header" style="background-color: #a2bae8;">
    <a href="../index.html">
      <img border=0 alt="NumPy" src="../_static/numpy_logo.png"></a>
    </div>
  </div>
</div>


    <div class="container">
      <div class="main">
        
	<div class="row-fluid">
	  <div class="span12">
	    <div class="spc-navbar">
              
    <ul class="nav nav-pills pull-left">
        <li class="active"><a href="https://numpy.org/">NumPy.org</a></li>
        <li class="active"><a href="https://numpy.org/doc">Docs</a></li>
        
        <li class="active"><a href="../index.html">NumPy v1.18 Manual</a></li>
        

          <li class="active"><a href="index.html" >NumPy Reference</a></li>
          <li class="active"><a href="routines.html" accesskey="U">Routines</a></li> 
    </ul>
              
              
    <ul class="nav nav-pills pull-right">
      <li class="active">
        <a href="../genindex.html" title="General Index"
           accesskey="I">index</a>
      </li>
      <li class="active">
        <a href="generated/numpy.dot.html" title="numpy.dot"
           accesskey="N">next</a>
      </li>
      <li class="active">
        <a href="generated/numpy.lib.format.html" title="numpy.lib.format"
           accesskey="P">previous</a>
      </li>
    </ul>
              
	    </div>
	  </div>
	</div>
        

	<div class="row-fluid">
      <div class="spc-rightsidebar span3">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Linear algebra (<code class="xref py py-mod docutils literal notranslate"><span class="pre">numpy.linalg</span></code>)</a><ul>
<li><a class="reference internal" href="#matrix-and-vector-products">Matrix and vector products</a></li>
<li><a class="reference internal" href="#decompositions">Decompositions</a></li>
<li><a class="reference internal" href="#matrix-eigenvalues">Matrix eigenvalues</a></li>
<li><a class="reference internal" href="#norms-and-other-numbers">Norms and other numbers</a></li>
<li><a class="reference internal" href="#solving-equations-and-inverting-matrices">Solving equations and inverting matrices</a></li>
<li><a class="reference internal" href="#exceptions">Exceptions</a></li>
<li><a class="reference internal" href="#linear-algebra-on-several-matrices-at-once">Linear algebra on several matrices at once</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="generated/numpy.lib.format.html"
                        title="previous chapter">numpy.lib.format</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="generated/numpy.dot.html"
                        title="next chapter">numpy.dot</a></p>
<div id="searchbox" style="display: none" role="search">
  <h4>Quick search</h4>
    <div>
    <form class="search" action="../search.html" method="get">
      <input type="text" style="width: inherit;" name="q" />
      <input type="submit" value="search" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
          <div class="span9">
            
        <div class="bodywrapper">
          <div class="body" id="spc-section-body">
            
  <span class="target" id="module-numpy.linalg"><span id="routines-linalg"></span></span><div class="section" id="linear-algebra-numpy-linalg">
<h1>Linear algebra (<a class="reference internal" href="#module-numpy.linalg" title="numpy.linalg"><code class="xref py py-mod docutils literal notranslate"><span class="pre">numpy.linalg</span></code></a>)<a class="headerlink" href="#linear-algebra-numpy-linalg" title="Permalink to this headline">¶</a></h1>
<p>The NumPy linear algebra functions rely on BLAS and LAPACK to provide efficient
low level implementations of standard linear algebra algorithms. Those
libraries may be provided by NumPy itself using C versions of a subset of their
reference implementations but, when possible, highly optimized libraries that
take advantage of specialized processor functionality are preferred. Examples
of such libraries are <a class="reference external" href="https://www.openblas.net/">OpenBLAS</a>, MKL (TM), and ATLAS. Because those libraries
are multithreaded and processor dependent, environmental variables and external
packages such as <a class="reference external" href="https://github.com/joblib/threadpoolctl">threadpoolctl</a> may be needed to control the number of threads
or specify the processor architecture.</p>
<div class="section" id="matrix-and-vector-products">
<h2>Matrix and vector products<a class="headerlink" href="#matrix-and-vector-products" title="Permalink to this headline">¶</a></h2>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.dot.html#numpy.dot" title="numpy.dot"><code class="xref py py-obj docutils literal notranslate"><span class="pre">dot</span></code></a>(a, b[, out])</p></td>
<td><p>Dot product of two arrays.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.linalg.multi_dot.html#numpy.linalg.multi_dot" title="numpy.linalg.multi_dot"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.multi_dot</span></code></a>(arrays)</p></td>
<td><p>Compute the dot product of two or more arrays in a single function call, while automatically selecting the fastest evaluation order.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.vdot.html#numpy.vdot" title="numpy.vdot"><code class="xref py py-obj docutils literal notranslate"><span class="pre">vdot</span></code></a>(a, b)</p></td>
<td><p>Return the dot product of two vectors.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.inner.html#numpy.inner" title="numpy.inner"><code class="xref py py-obj docutils literal notranslate"><span class="pre">inner</span></code></a>(a, b)</p></td>
<td><p>Inner product of two arrays.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.outer.html#numpy.outer" title="numpy.outer"><code class="xref py py-obj docutils literal notranslate"><span class="pre">outer</span></code></a>(a, b[, out])</p></td>
<td><p>Compute the outer product of two vectors.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.matmul.html#numpy.matmul" title="numpy.matmul"><code class="xref py py-obj docutils literal notranslate"><span class="pre">matmul</span></code></a>(x1, x2, /[, out, casting, order, …])</p></td>
<td><p>Matrix product of two arrays.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.tensordot.html#numpy.tensordot" title="numpy.tensordot"><code class="xref py py-obj docutils literal notranslate"><span class="pre">tensordot</span></code></a>(a, b[, axes])</p></td>
<td><p>Compute tensor dot product along specified axes.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.einsum.html#numpy.einsum" title="numpy.einsum"><code class="xref py py-obj docutils literal notranslate"><span class="pre">einsum</span></code></a>(subscripts, *operands[, out, dtype, …])</p></td>
<td><p>Evaluates the Einstein summation convention on the operands.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.einsum_path.html#numpy.einsum_path" title="numpy.einsum_path"><code class="xref py py-obj docutils literal notranslate"><span class="pre">einsum_path</span></code></a>(subscripts, *operands[, optimize])</p></td>
<td><p>Evaluates the lowest cost contraction order for an einsum expression by considering the creation of intermediate arrays.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.linalg.matrix_power.html#numpy.linalg.matrix_power" title="numpy.linalg.matrix_power"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.matrix_power</span></code></a>(a, n)</p></td>
<td><p>Raise a square matrix to the (integer) power <em class="xref py py-obj">n</em>.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.kron.html#numpy.kron" title="numpy.kron"><code class="xref py py-obj docutils literal notranslate"><span class="pre">kron</span></code></a>(a, b)</p></td>
<td><p>Kronecker product of two arrays.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="decompositions">
<h2>Decompositions<a class="headerlink" href="#decompositions" title="Permalink to this headline">¶</a></h2>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.linalg.cholesky.html#numpy.linalg.cholesky" title="numpy.linalg.cholesky"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.cholesky</span></code></a>(a)</p></td>
<td><p>Cholesky decomposition.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.linalg.qr.html#numpy.linalg.qr" title="numpy.linalg.qr"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.qr</span></code></a>(a[, mode])</p></td>
<td><p>Compute the qr factorization of a matrix.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.linalg.svd.html#numpy.linalg.svd" title="numpy.linalg.svd"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.svd</span></code></a>(a[, full_matrices, compute_uv, …])</p></td>
<td><p>Singular Value Decomposition.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="matrix-eigenvalues">
<h2>Matrix eigenvalues<a class="headerlink" href="#matrix-eigenvalues" title="Permalink to this headline">¶</a></h2>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.linalg.eig.html#numpy.linalg.eig" title="numpy.linalg.eig"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.eig</span></code></a>(a)</p></td>
<td><p>Compute the eigenvalues and right eigenvectors of a square array.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.linalg.eigh.html#numpy.linalg.eigh" title="numpy.linalg.eigh"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.eigh</span></code></a>(a[, UPLO])</p></td>
<td><p>Return the eigenvalues and eigenvectors of a complex Hermitian (conjugate symmetric) or a real symmetric matrix.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.linalg.eigvals.html#numpy.linalg.eigvals" title="numpy.linalg.eigvals"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.eigvals</span></code></a>(a)</p></td>
<td><p>Compute the eigenvalues of a general matrix.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.linalg.eigvalsh.html#numpy.linalg.eigvalsh" title="numpy.linalg.eigvalsh"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.eigvalsh</span></code></a>(a[, UPLO])</p></td>
<td><p>Compute the eigenvalues of a complex Hermitian or real symmetric matrix.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="norms-and-other-numbers">
<h2>Norms and other numbers<a class="headerlink" href="#norms-and-other-numbers" title="Permalink to this headline">¶</a></h2>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.linalg.norm.html#numpy.linalg.norm" title="numpy.linalg.norm"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.norm</span></code></a>(x[, ord, axis, keepdims])</p></td>
<td><p>Matrix or vector norm.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.linalg.cond.html#numpy.linalg.cond" title="numpy.linalg.cond"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.cond</span></code></a>(x[, p])</p></td>
<td><p>Compute the condition number of a matrix.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.linalg.det.html#numpy.linalg.det" title="numpy.linalg.det"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.det</span></code></a>(a)</p></td>
<td><p>Compute the determinant of an array.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.linalg.matrix_rank.html#numpy.linalg.matrix_rank" title="numpy.linalg.matrix_rank"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.matrix_rank</span></code></a>(M[, tol, hermitian])</p></td>
<td><p>Return matrix rank of array using SVD method</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.linalg.slogdet.html#numpy.linalg.slogdet" title="numpy.linalg.slogdet"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.slogdet</span></code></a>(a)</p></td>
<td><p>Compute the sign and (natural) logarithm of the determinant of an array.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.trace.html#numpy.trace" title="numpy.trace"><code class="xref py py-obj docutils literal notranslate"><span class="pre">trace</span></code></a>(a[, offset, axis1, axis2, dtype, out])</p></td>
<td><p>Return the sum along diagonals of the array.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="solving-equations-and-inverting-matrices">
<h2>Solving equations and inverting matrices<a class="headerlink" href="#solving-equations-and-inverting-matrices" title="Permalink to this headline">¶</a></h2>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.linalg.solve.html#numpy.linalg.solve" title="numpy.linalg.solve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.solve</span></code></a>(a, b)</p></td>
<td><p>Solve a linear matrix equation, or system of linear scalar equations.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.linalg.tensorsolve.html#numpy.linalg.tensorsolve" title="numpy.linalg.tensorsolve"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.tensorsolve</span></code></a>(a, b[, axes])</p></td>
<td><p>Solve the tensor equation <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">x</span> <span class="pre">=</span> <span class="pre">b</span></code> for x.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.linalg.lstsq.html#numpy.linalg.lstsq" title="numpy.linalg.lstsq"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.lstsq</span></code></a>(a, b[, rcond])</p></td>
<td><p>Return the least-squares solution to a linear matrix equation.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.linalg.inv.html#numpy.linalg.inv" title="numpy.linalg.inv"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.inv</span></code></a>(a)</p></td>
<td><p>Compute the (multiplicative) inverse of a matrix.</p></td>
</tr>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.linalg.pinv.html#numpy.linalg.pinv" title="numpy.linalg.pinv"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.pinv</span></code></a>(a[, rcond, hermitian])</p></td>
<td><p>Compute the (Moore-Penrose) pseudo-inverse of a matrix.</p></td>
</tr>
<tr class="row-even"><td><p><a class="reference internal" href="generated/numpy.linalg.tensorinv.html#numpy.linalg.tensorinv" title="numpy.linalg.tensorinv"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.tensorinv</span></code></a>(a[, ind])</p></td>
<td><p>Compute the ‘inverse’ of an N-dimensional array.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="exceptions">
<h2>Exceptions<a class="headerlink" href="#exceptions" title="Permalink to this headline">¶</a></h2>
<table class="longtable docutils align-default">
<colgroup>
<col style="width: 10%" />
<col style="width: 90%" />
</colgroup>
<tbody>
<tr class="row-odd"><td><p><a class="reference internal" href="generated/numpy.linalg.LinAlgError.html#numpy.linalg.LinAlgError" title="numpy.linalg.LinAlgError"><code class="xref py py-obj docutils literal notranslate"><span class="pre">linalg.LinAlgError</span></code></a></p></td>
<td><p>Generic Python-exception-derived object raised by linalg functions.</p></td>
</tr>
</tbody>
</table>
</div>
<div class="section" id="linear-algebra-on-several-matrices-at-once">
<span id="routines-linalg-broadcasting"></span><h2>Linear algebra on several matrices at once<a class="headerlink" href="#linear-algebra-on-several-matrices-at-once" title="Permalink to this headline">¶</a></h2>
<div class="versionadded">
<p><span class="versionmodified added">New in version 1.8.0.</span></p>
</div>
<p>Several of the linear algebra routines listed above are able to
compute results for several matrices at once, if they are stacked into
the same array.</p>
<p>This is indicated in the documentation via input parameter
specifications such as <code class="docutils literal notranslate"><span class="pre">a</span> <span class="pre">:</span> <span class="pre">(...,</span> <span class="pre">M,</span> <span class="pre">M)</span> <span class="pre">array_like</span></code>. This means that
if for instance given an input array <code class="docutils literal notranslate"><span class="pre">a.shape</span> <span class="pre">==</span> <span class="pre">(N,</span> <span class="pre">M,</span> <span class="pre">M)</span></code>, it is
interpreted as a “stack” of N matrices, each of size M-by-M. Similar
specification applies to return values, for instance the determinant
has <code class="docutils literal notranslate"><span class="pre">det</span> <span class="pre">:</span> <span class="pre">(...)</span></code> and will in this case return an array of shape
<code class="docutils literal notranslate"><span class="pre">det(a).shape</span> <span class="pre">==</span> <span class="pre">(N,)</span></code>. This generalizes to linear algebra
operations on higher-dimensional arrays: the last 1 or 2 dimensions of
a multidimensional array are interpreted as vectors or matrices, as
appropriate for each operation.</p>
</div>
</div>


          </div>
        </div>
          </div>
        </div>
      </div>
    </div>

    <div class="container container-navbar-bottom">
      <div class="spc-navbar">
        
      </div>
    </div>
    <div class="container">
    <div class="footer">
    <div class="row-fluid">
    <ul class="inline pull-left">
      <li>
        &copy; Copyright 2008-2019, The SciPy community.
      </li>
      <li>
      Last updated on Feb 20, 2020.
      </li>
      <li>
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 2.4.2.
      </li>
    </ul>
    </div>
    </div>
    </div>
  </body>
</html>